package com.deng.maintenance.viewhigh.view
{
	import com.deng.maintenance.model.MaintenanceModelLocator;
	import com.deng.maintenance.viewhigh.vo.OrgCbVo;
	
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	
	import mx.controls.CheckBox;
	import mx.events.FlexEvent;

	public class CBCB extends CheckBox
	{
		
		private var selVo:OrgCbVo;
		public function CBCB()
		{
			this.addEventListener(FlexEvent.CREATION_COMPLETE,showHandler);
			this.addEventListener(MouseEvent.MOUSE_UP,upEvt);
			this.addEventListener(FlexEvent.SHOW,showHandler);
			this.addEventListener(KeyboardEvent.KEY_DOWN,keyHandler);
			super();
		}
		private function keyHandler(event:KeyboardEvent):void
		{
			if(event.keyCode == 32)
			{
				event.stopImmediatePropagation();
				return;
			}
		}
		private function upEvt(event:MouseEvent):void{
			if(this.selected){//之前选中的，后面要删除
				selVo.new_organization_id = 0;
				(this.data as OrgCbVo).new_organization_id = 0;				
			}else{//之前没选中，后面要增加
				selVo.new_organization_id = MaintenanceModelLocator.getInstance().vhSelOrg.id;
				(this.data as OrgCbVo).new_organization_id = selVo.new_organization_id;
			}			
		}
		
		private function showHandler(evt:FlexEvent):void{
			selVo = this.data as OrgCbVo;
			if(selVo.new_organization_id > 0){
				this.selected = true;
			}else{
				this.selected = false;
			}			
		}
		
	}
}